package leetcode;

import org.junit.Test;

/**
 * @author cino
 * justCode
 */
public class leetcode35 {

    @Test
    public void test(){
        int[] array =  new int[]{1,3,5,6};
        System.out.println(searchInsert(array,2));
    }

    public static int searchInsert(int[] nums, int target) {
        int l=0,r=nums.length-1;
        while (l<=r){
            int mid = (l+r)/2;
            if (nums[mid]==target){
                return mid;
            } else if (nums[mid]<target) {
                l = mid+1;
            }else {
                r = mid-1;
            }
        }
        return l;
    }
}
